-
Notifications
You must be signed in to change notification settings - Fork 582
execute_plan
: don't build temporary vec of rows
#2918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
54e7434
to
b45b193
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good code, good comments, good benchmarks. A lot of this RowListBuilder
stuff could be moved out of the code-ownered websocket.rs
, IMO, since we're trying to restrict changes to the format of the messages, not the procedures by which they are constructed. But I don't think it needs to get moved, I'm just flagging it as an option.
I would like to review this before it merges.
In particular I may ask that we do this. |
I think we should split |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think it is an opportune time to move the non-spacetime types out of websocket.rs
. This file should really be reserved for the public message schemas only.
6271604
to
c134d82
Compare
io::{self, Read as _, Write as _}, | ||
sync::Arc, | ||
}; | ||
use std::sync::Arc; | ||
|
||
pub const TEXT_PROTOCOL: &str = "v1.json.spacetimedb"; | ||
pub const BIN_PROTOCOL: &str = "v1.bsatn.spacetimedb"; | ||
|
||
pub trait RowListLen { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move the entire trait out? Isn't the idea that we only want SpacetimeType
s in this file?
Description of Changes
Avoid building a temporary
Vec
inexecute_plan
by exposing a list-building interface instead.fn encode_list
is rewritten in terms of this list-building interface.BsatnRowList
andBsatnRowListBuilder
types are split into two entirely separate types. The latter now tries to recognize the case where there isn't a known static layout, but where the BSATN lengths happen to be the same for all rows anyways. In those cases, the allocation ofRowSizeHint::RowOffsets
is avoided in favor of just storing the found length in bytes. This is in particular useful for small table updates as statistically, the fewer rows, the more chance of the lengths being all equal. In the case of a single row, the chance is notably 100%. It is also good for the case of when we don't haveRelValue::Row
orRow::Ptr
but where the underlying table that actually has a static layout.In the future, we might want to avoid these lists in incremental as well.
Benchmarks
Benchmark numbers vs. master using
cargo bench --bench subscription -- --baseline subs
on i7-7700K, 64GB RAM:Performance goes from roughly 56.721 ms to 28.795 ms.
API and ABI breaking changes
None
Expected complexity level and risk
2, fairly local change to just subscriptions.
Testing
Covered by existing tests.